// import { resolve } from 'core-js/fn/promise'
import {
  ADD_COUNTER,
  ADD_TO_CART
} from './constant'


export default {
  addCart({ state, commit }, payload) {
    return new Promise((resolve, reject) => {
      let old = state.productList.find(item => item.iid === payload.iid)
      if (old) {
        commit(ADD_COUNTER, old)
        resolve('当前的商品数量+1！')
      } else {
        payload.count = 1
        payload.select = true
        commit(ADD_TO_CART, payload)
        resolve('添加商品成功！')
      }
    })
  }
}